package com.szbmyoubao.app.view.dialog

import android.view.LayoutInflater
import android.view.View
import androidx.fragment.app.FragmentActivity
import com.szbmyoubao.app.ui.webview.WebHelper
import com.ellecity06.common.base.BaseDialog
import com.ellecity06.cwhiskymall.databinding.DialogAgreementBinding

/**
 * @author ellecity06
 * @time 2024/11/7 14:39
 * @des 用户协议弹窗
 */
class AgreementDialog(
    private val activity: FragmentActivity,
    private val cancel: () -> Unit,
    private val confirm: () -> Unit
) :
    BaseDialog<DialogAgreementBinding>(activity),
    View.OnClickListener {
    override val isTouchOutsideDismiss: Boolean
        get() = false
    override val isCancelable: Boolean
        get() = false
    override val widthP: Float
        get() = 0.8F

    override fun inflaterViewBinding(): DialogAgreementBinding {
        return DialogAgreementBinding.inflate(LayoutInflater.from(context))
    }

    override fun initialize() {
        binding.tvUserAgreement.setOnClickListener(this)
        binding.tvPrivateAgreement.setOnClickListener(this)
        binding.tvDgcCancel.setOnClickListener(this)
        binding.tvDgcConfirm.setOnClickListener(this)
    }

    override fun onClick(view: View?) {
        when (view?.id) {
            binding.tvUserAgreement.id -> {
                WebHelper.Companion.toUserAgreement(activity)
            }
            binding.tvPrivateAgreement.id -> {
                WebHelper.Companion.toPrivateAgreement(activity)
            }
            binding.tvDgcCancel.id -> {
                dismiss()
                cancel.invoke()
            }
            binding.tvDgcConfirm.id -> {
                dismiss()
                confirm.invoke()
            }
        }
    }
}